programming4us
           
 
 
Programming

Coding JavaScript for Mobile Browsers (part 1) - Standard dialogs

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
12/24/2010 2:44:05 PM

2. JavaScript Mobile Compatibility

As you move into JavaScript on the mobile web, you’ll want to test compatibility and use some old-fashioned features.

2.1. Feature detection

The simplest way to detect if a feature, API, function, or object is available to use is to ask if it exists using a simple if statement:

if (object) {
// Object available
}

For example:

if (document.getElementById) {
// DOM function available
}


Warning:

Even on JavaScript-compatible devices, a script might not work because of the user’s (or company’s) profile. For example, BlackBerry devices have the option to disallow JavaScript from the browser or from the company policies. You should always present a non-JavaScript version of your site’s functionality.


2.2. Standard dialogs

JavaScript supports a list of standard dialogs that are undervalued in modern desktop websites, often being replaced by Dynamic HTML or UI libraries. They make great standard dialogs for use in mobile websites, though, as shown in Figure 1.

Figure 1. Using standard JavaScript dialogs you will get free rich and multiplatform interfaces, using UI controls from the operating system.


The list of available dialogs is:

  • alert, for showing a message

  • confirm, for receiving a Boolean response from the user

  • prompt, for receiving a string from the user

  • print, for sending the web page to the printer

  • find, for invoking the find feature of the browser

The find dialog isn’t really part of the standard, but it works in almost every non-IE desktop web browser on the market. This dialog receives three optional parameters: the text to find, a case-sensitive Boolean, and a backwards Boolean. In general, it should be avoided in mobile browsers. Most of them don’t have a search feature.

The print dialog isn’t mobile compatible, for obvious reasons, but the alert, confirm, and prompt dialogs are compatible with almost every JavaScript-enabled mobile phone (as Table 3 shows). I encourage you to use them when needed. Using a standard dialog will always be quicker, simpler, nicer, and more compatible than using any other solution for the same task.

Table 3. Standard dialog support compatibility table
Browser/platformalert, confirm, prompt
SafariYes
Android browserYes
Symbian/S60Yes
Nokia Series 40Yes
webOSYes
BlackBerryYes
NetFrontYes
Internet ExplorerYes
Motorola Internet BrowserYes
Opera MobileYes
Opera MiniYes, rendered on the server

Common problems with the alert dialog (and the others) are the usage of the carriage return for multiline text, and how to display text that’s too big to fit in the available space. For the first problem, it is common in desktop JavaScript to use the \n (newline) escape special character. (There are other special escape characters, too, like \t for tabulation.) Let’s see what happens with both problems in mobile browsers. Table 8-4 reports on their support for newlines and large amounts of text in dialogs, and Figure 2 shows the use of a scrolling area that supports long text.

Figure 2. On some browsers, big alerts have scrollbars (or can be scrolled with a finger, on touch devices).


Table 4. Multiple lines and scrolling text in alerts compatibility table
Browser/platform\n in alertsScrolling support for long text
SafariYesYes, change alert appearance with scroll support
Android browserYesScroll
Symbian/S60YesScroll
Nokia Series 40YesScroll
webOSNo, shows one lineNo, text overflow screen without scroll
BlackBerryYesScroll
NetFrontYesAutoscroll
Internet ExplorerYesScroll
Motorola Internet BrowserYesScroll
Opera MobileYesScroll
Opera MiniYesScroll


Note:

For usability reasons, if a device has a numeric keyboard it is best to use a normal text input with numeric capabilities, rather than a selection list. Remember that a numeric keyboard is useful for numeric entries.

Other -----------------
- Programming the Mobile Web : JavaScript Mobile - Supported Technologies
- Security in Cloud Computing (part 4) - Audit and Compliance
- Security in Cloud Computing (part 3)
- Security in Cloud Computing (part 2) - Identity and Access Management
- Security in Cloud Computing (part 1) - Data Security and Storage
- Cloud Security and Privacy : Analyst Predictions
- CSS for Mobile Browsers : WebKit Extensions (part 2) - Border Image
- CSS for Mobile Browsers : WebKit Extensions (part 1) - Text Stroke and Fill
- jQuery 1.3 : Working with numeric form data (part 9) - The finished code
- jQuery 1.3 : Working with numeric form data (part 8) - Editing shipping information
- jQuery 1.3 : Working with numeric form data (part 7) - Deleting items
- jQuery 1.3 : Working with numeric form data (part 6) - Finishing touches
- jQuery 1.3 : Working with numeric form data (part 5)
- jQuery 1.3 : Working with numeric form data (part 4) - Dealing with decimal places
- jQuery 1.3 : Working with numeric form data (part 3) - Parsing and formatting currency
- jQuery 1.3 : Working with numeric form data (part 2)
- jQuery 1.3 : Working with numeric form data (part 1) - Shopping cart table structure
- The Art of SEO : Controlling Content with Cookies and Session IDs
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 5) - The Freehand Tool
- iPad SDK : New Graphics Functionality - We Are All Tool Users (part 4) - The Ellipse and Rectangle Tools
 
 
 
Top 10
 
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
- First look: Apple Watch

- 3 Tips for Maintaining Your Cell Phone Battery (part 1)

- 3 Tips for Maintaining Your Cell Phone Battery (part 2)
programming4us programming4us